<?php

/**
 * 
 */
class Ueditor extends CWidget
{
	
	/******* widget private vars *******/
	private $baseUrl = null;

	public $getId = 'editor';

	public $options = NULL;
	
	/**
	* Initialize the widget
	*/
	public function init()
	{
		//Publish assets
		$this->publishAssets();
		$this->registerClientScripts();
		parent::init();
	}
	
	/**
	* Publishes the assets
	*/
	public function publishAssets()
	{
		$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'utf8-php';
		$this->baseUrl = Yii::app()->getAssetManager()->publish($dir);
	}
	
	/**
	* Registers the external javascript files
	*/
	public function registerClientScripts()
	{
        echo '<script id="'.$this->getId.'" name="content" type="text/plain"></script>';
        echo '<link rel="stylesheet" type="text/css" href="/admin/protected/extensions/ueditor/utf8-php/themes/default/css/ueditor.css">';
        echo '<script type="text/javascript" src="/admin/protected/extensions/ueditor/utf8-php/ueditor.config.js"></script>';
        echo '<script type="text/javascript" src="/admin/protected/extensions/ueditor/utf8-php/ueditor.all.js"></script>';
        echo '<script type="text/javascript">var ue = UE.getEditor('.$this->getId.',{'.$this->options.'});</script>';

	}
	/**
	* Run the widget
	*/
	public function run()
	{
			
		parent::run();
	}
}
